package graphics;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

/**
 * Class StartPanel
 * The First Screen seen when starting the game
 *
 * @author Jared Moore and Chris Gordon
 */
public class StartPanel extends JPanel
{
    private JFrame frame;

	/**
	 * Constructor for StartPanel
	 * Builds a new StartPanel
	 */
	public StartPanel()
    {
		super();

        try
        {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        }
        catch (ClassNotFoundException | InstantiationException
                | IllegalAccessException | UnsupportedLookAndFeelException e)
        {
            System.err.println("You have an issue with your system");
            e.printStackTrace();
            System.exit(1);
            //if one of these errors are thrown, there is a significant problem with your computer
            //your computer either cannot tell how it formats windows or it cannot use its own theme
        }
		setBackground(Color.BLACK);	
		setFocusable(true);
		setPreferredSize(new Dimension(800,600));
        addKeyListener(new KeyAdapter() {
            @Override
            public void keyTyped(KeyEvent keyEvent)
            {
                if (keyEvent.getKeyCode() == 0)
                {
                    MainMenuPanel panel = new MainMenuPanel();
                    frame.setContentPane(panel);
                    panel.setFrame(frame);
                    removePanel();
                    frame.pack();
                    frame.setSize(new Dimension(800,600));
                }
            }
        });
	}

	/**
	 * Draws the Panel
	 * @param g Graphics object used to paint elements on the screen
	 */
	public void paintComponent(Graphics g)
    {
		super.paintComponent(g);

		g.drawString("MULE", 370, 200);
		g.drawString("Press Enter", 350, 350);
	}

	/**
	 * Removes this panel from the frame in which it resides
	 */
    private void removePanel()
    {
        frame.remove(this);
    }

    /**
     * Setter for frame
     * @param frame    The frame to set
     */
    public void setFrame(JFrame frame) {
        this.frame = frame;
    }

	/**
	 * Main method
	 * Runs the game
	 * @param args Unused
	 */
	public static void main(String[] args)
	{
		JFrame frame = new JFrame();
		StartPanel panel = new StartPanel();
		frame.setTitle("Mule");
		frame.setSize(800, 600);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setContentPane(panel);
		frame.setVisible(true);
		panel.setFrame(frame);
	}
}
